//
//  GKShareHander.m
//  jinwan
//
//  Created by GKiOS on 2017/6/7.
//  Copyright © 2017年 wy. All rights reserved.
//

#import "GKShareHander.h"
#import "MBProgressHUD+SG.h"
@implementation GKShareHander
+ (void)showShareMenuWithShareObject:(UMSocialMessageObject *)shareObject
{
    [self showShareMenuWithShareObject:shareObject completion:nil];
}

+ (void)showShareMenuWithShareObject:(UMSocialMessageObject *)shareObject completion:(void (^)(id, NSError *))completion
{
    [GKShareHander confingurePreSharePlatforms];
    [UMSocialUIManager showShareMenuViewInWindowWithPlatformSelectionBlock:^(UMSocialPlatformType platformType, NSDictionary *userInfo) {
        [GKShareHander shareWebPageToPlatformType:platformType shareObject:shareObject completion:nil];
    }];
    
}

+ (void)shareWebPageToPlatformType:(UMSocialPlatformType)platformType shareObject:(UMSocialMessageObject *)shareObject completion:(void (^)(id, NSError *))completionBlock
{
    [[UMSocialManager defaultManager] shareToPlatform:platformType messageObject:shareObject currentViewController:nil completion:^(id result, NSError *error) {
        if (error) {
            UMSocialLogInfo(@"************Share fail with error %@*********",error);
            NSString *userInfoMessgae = [error valueForKeyPath:@"userInfo.message"];
            [MBProgressHUD SG_showMBProgressHUDWithOnlyMessage:userInfoMessgae delayTime:1.5];
        }else{
            if ([result isKindOfClass:[UMSocialShareResponse class]]) {
                UMSocialShareResponse *resp = result;
                //分享结果消息
                UMSocialLogInfo(@"response message is %@",resp.message);
                //第三方原始返回的数据
                UMSocialLogInfo(@"response originalResponse data is %@",resp.originalResponse);
            }else{
                UMSocialLogInfo(@"response data is %@",result);
            }
        }
        if (completionBlock) {
            completionBlock(result, error);
        }
    }];
}

+ (void)confingurePreSharePlatforms
{
    [UMSocialUIManager setPreDefinePlatforms:
                                              @[
                                               @(UMSocialPlatformType_WechatSession),
                                               @(UMSocialPlatformType_WechatTimeLine),
                                               @(UMSocialPlatformType_Qzone),
                                               @(UMSocialPlatformType_QQ)
                                               ]
     ];
}
@end
